




/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.LgTablesManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MP.LayerHelper.MP_OBS.BLL
{
	public class LgTablesManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public LgTablesManagerBase()
		{
			// Nothing for now.
		}
		
		public override string TableName()
        {
            return "LgTables";
        }
		
		public LgTablesEntity Insert(LgTablesEntity _LgTablesEntity)
		{
			return Insert(_LgTablesEntity, "");
		}
		
		public LgTablesEntity Insert(LgTablesEntity _LgTablesEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_LgTablesEntity, true);
				LgTablesFields field = new LgTablesFields();
                LogEntity(_LgTablesEntity, field, AcInsert, controlId);
			}
			return _LgTablesEntity;
		}

		
		public LgTablesEntity Insert(Guid Id, string TableName, string Description, bool IsLog)
		{
			LgTablesEntity _LgTablesEntity = new LgTablesEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_LgTablesEntity.Id = Id;
				_LgTablesEntity.TableName = TableName;
				_LgTablesEntity.Description = Description;
				_LgTablesEntity.IsLog = IsLog;
				LgTablesFields field = new LgTablesFields();
                LogEntity(_LgTablesEntity, field, AcInsert);
				adapter.SaveEntity(_LgTablesEntity, true);
			}
			return _LgTablesEntity;
		}

		public LgTablesEntity Insert(string TableName, string Description, bool IsLog)
		{
			LgTablesEntity _LgTablesEntity = new LgTablesEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_LgTablesEntity.TableName = TableName;
				_LgTablesEntity.Description = Description;
				_LgTablesEntity.IsLog = IsLog;
				adapter.SaveEntity(_LgTablesEntity, true);
				LgTablesFields field = new LgTablesFields();
                LogEntity(_LgTablesEntity, field, AcInsert);
			}
			return _LgTablesEntity;
		}
		
		public bool Update(LgTablesEntity _LgTablesEntity)
        {
            return Update(_LgTablesEntity, "");
        }

		public bool Update(LgTablesEntity _LgTablesEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(LgTablesFields.Id == _LgTablesEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_LgTablesEntity, filter);
				toReturn = true;
				
				LgTablesFields field = new LgTablesFields();
                LogEntity(_LgTablesEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(LgTablesEntity _LgTablesEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_LgTablesEntity, filter);
				toReturn = true;
				
				LgTablesFields field = new LgTablesFields();
                LogEntity(_LgTablesEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(Guid Id, string TableName, string Description, bool IsLog)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LgTablesEntity _LgTablesEntity = new LgTablesEntity(Id);
				if (adapter.FetchEntity(_LgTablesEntity))
				{
				
					_LgTablesEntity.TableName = TableName;
					_LgTablesEntity.Description = Description;
					_LgTablesEntity.IsLog = IsLog;
					adapter.SaveEntity(_LgTablesEntity, true);
					toReturn = true;
					
					LgTablesFields field = new LgTablesFields();
					LogEntity(_LgTablesEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(Guid Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LgTablesEntity _LgTablesEntity = new LgTablesEntity(Id);
				if (adapter.FetchEntity(_LgTablesEntity))
				{
					adapter.DeleteEntity(_LgTablesEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("LgTablesEntity", null);
			}
		}
		
		
		public int DeleteById(Guid Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LgTablesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTableName(string TableName)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.TableName == TableName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LgTablesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDescription(string Description)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LgTablesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIsLog(bool IsLog)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.IsLog == IsLog);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LgTablesEntity", filter);
			}
			return toReturn;
		}
		

		
		public LgTablesEntity SelectOne(Guid Id)
		{
			LgTablesEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LgTablesEntity _LgTablesEntity = new LgTablesEntity(Id);
				if (adapter.FetchEntity(_LgTablesEntity))
				{
					toReturn = _LgTablesEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectAllLST()
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, null, 0, null);
			}
			return _LgTablesCollection;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _LgTablesCollection;
		}


		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByIdLST(Guid Id)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null);
			}
			return _LgTablesCollection;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByIdLST_Paged(Guid Id, int PageNumber, int PageSize)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LgTablesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(Guid Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(Guid Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByTableNameLST(string TableName)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.TableName == TableName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null);
			}
			return _LgTablesCollection;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByTableNameLST_Paged(string TableName, int PageNumber, int PageSize)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.TableName == TableName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LgTablesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTableNameRDT(string TableName)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.TableName == TableName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByTableNameRDT_Paged(string TableName, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.TableName == TableName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByDescriptionLST(string Description)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null);
			}
			return _LgTablesCollection;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByDescriptionLST_Paged(string Description, int PageNumber, int PageSize)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LgTablesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDescriptionRDT(string Description)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByDescriptionRDT_Paged(string Description, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByIsLogLST(bool IsLog)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.IsLog == IsLog);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null);
			}
			return _LgTablesCollection;
		}
		
		// Return EntityCollection<LgTablesEntity>
		public EntityCollection<LgTablesEntity> SelectByIsLogLST_Paged(bool IsLog, int PageNumber, int PageSize)
		{
			EntityCollection<LgTablesEntity> _LgTablesCollection = new EntityCollection<LgTablesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.IsLog == IsLog);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LgTablesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LgTablesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIsLogRDT(bool IsLog)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.IsLog == IsLog);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIsLogRDT_Paged(bool IsLog, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LgTablesCollection = new EntityCollection(new LgTablesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LgTablesFields.IsLog == IsLog);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LgTablesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
